package com.kiven.swing;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

import static com.kiven.swing.SwingConsole.*;

public class HelloButton extends JFrame {
	private JButton b1 = new JButton("Button1");
	private JButton b2 = new JButton("Button2");
	
	private JTextField txt = new JTextField(10);
	
	class ButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			String name = ((JButton) e.getSource()).getText();
			txt.setText(name);
		}
	}
			
	private ButtonListener bl = new ButtonListener();
	
	public HelloButton() {
		b1.addActionListener(bl);
		b2.addActionListener(bl);
		
		this.setLayout(new FlowLayout());
		this.add(b1);
		this.add(txt);
		this.add(b2);
	}
	
	public static void main(String[] args) {
		run(new HelloButton(),400,500);
	}

}
